package tool.zyk.consts;

import lombok.AllArgsConstructor;
import lombok.Getter;
import tool.zyk.dto.RpcOrderTypeDTO;

import java.util.Arrays;
import java.util.Objects;

/**
 * RPC指令类型
 */
@Getter
@AllArgsConstructor
public enum RpcOrderTypeEnum {
    REQUEST(1, "请求"),
    RESPONSE(2, "响应"),
    ;

    private final Integer orderType;
    private final String desc;

    public static RpcOrderTypeEnum findByOrderType(Integer type) {
        return Arrays.stream(values())
                .filter(a -> Objects.equals(a.getOrderType(), type))
                .findFirst()
                .orElseThrow(() -> new RuntimeException("未知指令类型"));
    }

    public RpcOrderTypeDTO ofDto() {
        RpcOrderTypeDTO rpcOrderTypeDTO = new RpcOrderTypeDTO();
        rpcOrderTypeDTO.setOrderType(this.getOrderType());
        rpcOrderTypeDTO.setDesc(this.getDesc());
        return rpcOrderTypeDTO;
    }


}
